package com.zibo.convalesce.common.result;

import java.util.HashMap;


public class AjaxMapResult extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public AjaxMapResult() {
    }

    /**
     * 500 ---  操作失败
     */
    public static AjaxMapResult error() {
        return error(500, "操作失败");
    }

    /**
     * 500 --- msg
     */
    public static AjaxMapResult error(String msg) {
        return error(500, msg);
    }

    /**
     * code --- msg
     */
    public static AjaxMapResult error(int code, String msg) {
        AjaxMapResult json = new AjaxMapResult();
        json.put("code", code);
        json.put("msg", msg);
        return json;
    }


    public static AjaxMapResult success(int code, String msg) {
        AjaxMapResult json = new AjaxMapResult();
        json.put("code", code);
        json.put("msg", msg);
        return json;
    }


    /**
     * 200 --- msg
     */
    public static AjaxMapResult success(String msg) {
        AjaxMapResult json = new AjaxMapResult();
        json.put("msg", msg);
        json.put("code", 200);
        return json;
    }

    /**
     * 200 --- 操作成功
     */
    public static AjaxMapResult success() {
        return AjaxMapResult.success("操作成功");
    }


    public static AjaxMapResult successData(long total, Object value) {
        AjaxMapResult json = new AjaxMapResult();
        json.put("code", 0);
        json.put("msg", "操作成功");
        json.put("count", total);
        json.put("data", value);
        return json;
    }

    public static AjaxMapResult errorData(long total, Object data) {
        AjaxMapResult json = new AjaxMapResult();
        json.put("code", 500);
        json.put("msg", "操作失败");
        json.put("count", total);
        json.put("data", data);
        return json;
    }


    /**
     * put( k, v)
     */
    @Override
    public AjaxMapResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
